import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home'),
    redirect: 'all',
    children: [
      {
        path: 'all',
        component: () => import('@/views/AllRoom')
      },
      {
        path: 'single',
        component: () => import('@/views/SingleRoom')
      },
      {
        path: 'double',
        component: () => import('@/views/DoubleRoom')
      },
      {
        path: 'more',
        component: () => import('@/views/MoreRoom')
      },
      {
        path: 'order/:roomId',
        component: () => import('@/views/OrderRoom')
      },
      {
        path: '/stat',
        component: () => import('@/views/Stat')
      },
      {
        path: '/add',
        component: ()=> import('@/views/AddAdmin')
      },
      {
        path: '/register',
        component: ()=> import('@/views/VipRegister')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/LoginPage')
  }

]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// loading chunk 出错处理
// router.onError((error) => {
//   const pattern = /Loading chunk (\d)+ failed/g
//   const isChunkLoadFailed = error.message.match(pattern)
//   const targetPath = router.history.pending.fullPath
//   if (isChunkLoadFailed) {
//     router.replace(targetPath)
//   }
// })

export default router
